#ifndef _NETSTM_H_
#define _NETSTM_H_
#include "../define/define.h"

class ByteStream
{
public :
  ByteStream(uint8* buf = NULL, uint32 offset = 0, uint32 buf_size = 0);
   ~ByteStream();

  void Attach(uint8* buf, uint32 offset, uint32 buf_size);
  uint32 Seek(uint32 pos);
  uint32 Skip(uint32 dis);
  uint32 Tell();
  int UsableBytes();
  uint8* get_buf();
  void Write(void* data, uint32 length);
  void Read(void* data, uint32 length);
  void Modify(uint32 offset,void* data, uint32 length);
  void Modify_uint32(uint32 offset,uint32 data);
  ByteStream& operator << (uint8 ch);
  ByteStream& operator << (uint16 s);
  ByteStream& operator << (uint32 l);
  ByteStream& operator << (char* str);
  ByteStream& operator << (const char str[]);
  ByteStream& operator >> (uint8& ch);
  ByteStream& operator >> (char& ch);
  ByteStream& operator >> (uint16& s);
  ByteStream& operator >> (uint32& l);
  ByteStream& operator >> (char*& str);
  char* ReadString(uint16 max_len);
  void ReadString(char* str, uint16 max_len);

  static void Swap(void* data, int length);
  bool is_valid_data() { return m_is_valid_data; }

protected :
  uint8* m_buf;
  uint32 m_cur_pos;
  uint32 m_buf_size;
  bool m_is_valid_data;
};

#endif
